package lzzy.com;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;


import java.time.LocalDate;

public class MyJavaFX_A extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        // 2.0.AnchorPane布局
        AnchorPane apTop = new AnchorPane();
        apTop.setStyle("-fx-background-color:#CCCCCC");
        AnchorPane apLeft = new AnchorPane();
        apLeft.setStyle("-fx-background-color:#66CCCC");
        AnchorPane apBottom = new AnchorPane();
        apBottom.setStyle("-fx-background-color:#11CCCC");
        AnchorPane apRight = new AnchorPane();
        apRight.setStyle("-fx-background-color:#CCCCCC");
        apRight.setPrefWidth(200);
        AnchorPane apCenter = new AnchorPane();
        // 3.0主界面 输入框等
        // 3.1四个输入框,以及提示
        Label y_name = new Label("姓名:");
        y_name.setFont(Font.font(15));
        TextField e_name = new TextField();
        e_name.setPrefWidth(100);

        Label y_gender = new Label("性别:");
        y_gender.setFont(Font.font(15));
//		TextField e_gender = new TextField();
        ChoiceBox<String> e_gender = new ChoiceBox<String>();
        e_gender.getItems().addAll("男", "女");
        e_gender.setPrefWidth(100);

        Label y_age = new Label("出生日期:");
        y_age.setFont(Font.font(15));
        DatePicker e_age = new DatePicker();
        e_age.setPrefWidth(100);

        Label y_date = new Label("日期:");
        y_date.setFont(Font.font(15));
        DatePicker e_date = new DatePicker();
        e_date.setValue(LocalDate.now());
        e_date.setPrefWidth(100);
        // 3.2网格布局 基本信息
        GridPane gridPane = new GridPane();
        gridPane.setPrefWidth(756);
        // 3.3给布局添加元素
        gridPane.add(y_name, 0, 0);
        gridPane.add(e_name, 1, 0);
        gridPane.add(y_gender, 2, 0);
        gridPane.add(e_gender, 3, 0);
        gridPane.add(y_age, 4, 0);
        gridPane.add(e_age, 5, 0);
        gridPane.add(y_date, 6, 0);
        gridPane.add(e_date, 7, 0);
        // 3.4设置水平及垂直的边距，以及外边距
        gridPane.setHgap(20);
        gridPane.setVgap(20);
        // 3.4设置内边距
        gridPane.setPadding(new Insets(10));
        // 3.5设置边框
        gridPane.setStyle("-fx-border-color: #b1b1b1 #b1b1b1 #b1b1b1 #b1b1b1;-fx-border-width: 1px");

        apCenter.getChildren().addAll(gridPane);//多个

        //方位布局;
        BorderPane bor = new BorderPane();
        bor.setCenter(apCenter);
        Button saveButton = new Button("保存");
        Button printButton = new Button("打印");
        // 2.3设置对齐方式
        BorderPane.setAlignment(printButton, Pos.CENTER);
        BorderPane.setAlignment(saveButton, Pos.CENTER);
        saveButton.setPrefWidth(85);//设置按钮大小:宽
        saveButton.setPrefHeight(85);
        // 仅保存
        saveButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                // 1.收集信息-------加到对象中----------------------------
                Glands glands = new Glands();
                glands.setE_name(e_name.getText());// 姓名
                glands.setE_gender(e_gender.getValue());// 性别
                glands.setE_age(e_age.getValue().toString());// 年龄
                glands.setE_date(e_date.getValue().toString());// 日期

            }
        });





        // 2.4.界面
        Scene scene = new Scene(bor);
        primaryStage.setScene(scene);
        primaryStage.setTitle("一个页面");
        primaryStage.setHeight(1000);
        primaryStage.setWidth(1000);
        primaryStage.show();

    }


}
class Glands {
    public Glands() {
    }

    public void setE_name(String text) {
    }

    public void setE_gender(String value) {
    }

    public void setE_age(String toString) {
    }

    public void setE_date(String toString) {
    }
}